import { Injectable } from '@angular/core';
import {
  HttpEvent, HttpInterceptor, HttpHandler, HttpRequest
} from '@angular/common/http';

import { Observable } from 'rxjs';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler):
    Observable<HttpEvent<any>> {

      const temUrl = req.url.indexOf('4200') > 0 ? req.url.replace('4200', '3333') : req.url;

      const secureReq = req.clone({
        url: temUrl,
        setHeaders: {
          'Content-Type': 'application/json',
        },
      });

      return next.handle(secureReq);
  }
}
